//
//  MSMemberServeCell.m
//  SocietySale
//
//  Created by yumingwei on 2016/11/26.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSMemberServeCell.h"

@interface MSMemberServeCell ()
@property (nonatomic, strong) UIButton *continueBtn;
@end

@implementation MSMemberServeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.textLabel.font = HeitiFont(14);
    
    self.continueBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-92, 10, 80, 30)];
    self.continueBtn.titleLabel.font = HeitiFont(16);
    [self.continueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.continueBtn.layer.cornerRadius = 2;
    [self.continueBtn addTarget:self action:@selector(continueClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.continueBtn];
    
    _horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(12, 43.4, SCREEN_WIDTH-24, 0.4)];
    _horizonLineView.backgroundColor = kNormalGray;
    [self.contentView addSubview:_horizonLineView];
}

- (void)setModel:(MSCommonModel *)model{
    _model = model;
    
    NSString *dayStr = [NSString stringWithFormat:@"%@天",model.title];
    NSMutableAttributedString *titleAttStr = [[NSMutableAttributedString alloc] initWithString:dayStr];
    NSAttributedString *coinValue = [[NSAttributedString alloc] initWithString:model.subTitle attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:UIColorFromRGB(0xcaa562)}];
    NSAttributedString *unit = [[NSAttributedString alloc] initWithString:@"江湖币"];
    [titleAttStr appendAttributedString:coinValue];
    [titleAttStr appendAttributedString:unit];
    
    self.textLabel.attributedText = titleAttStr;
    
    NSString *btnTitle = [model.thirdTitle isEqualToString:@"升级"]?@"升级":@"续费";
    UIColor *btnBackColor = [model.thirdTitle isEqualToString:@"升级"]?UIColorFromRGB(0xe8ab57):UIColorFromRGB(0xe8ab57);
    [self.continueBtn setTitle:btnTitle forState:UIControlStateNormal];
    self.continueBtn.backgroundColor = btnBackColor;
}

- (void)setRowIndex:(NSInteger)rowIndex{
    _rowIndex = rowIndex;
}

- (void)continueClick{
    if ([self.delegate respondsToSelector:@selector(selectBtnWithIndex:)]) {
        [self.delegate selectBtnWithIndex:_rowIndex];
    }
}

@end
